<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/01/25 15:39:50 $)
// $RCSfile: index.php,v $ : $Revision: 1.2 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

define("SWIFT_AREA", 130);

if (defined("SWIFTCUSTOMPATH"))
{
	chdir(SWIFTCUSTOMPATH);
} else {
	chdir('./../');
}
require_once ("./swift.php");

$template->assign("ismonitor", true);

if ($_REQUEST["_ca"] == "login") {
	/*
	* #########################################################
	* Authenticate User, Insert session and redirect else just display login form
	* #########################################################
	*/
	$staffid = $staffauth->authenticate($_REQUEST["username"], $_REQUEST["password"]);
	if (!empty($staffid))
	{
		require_once ("./includes/functions_html.php");

		// Authentication successfull, Generate a sessionid for this user
		$session->insertSession(SESSION_MONITOR, $staffid);

		printRedirect($_SWIFT["language"]["redirect_dashboard"], "index.php?_m=livesupport&_a=monitordashboard");
	} else {
		echo "Auth Failure";
	}
} else if ($_REQUEST["_ca"] == "logout") {
	$result = $session->logoutSession(SESSION_MONITOR);

	$staffauth->displayLoginForm(iif($result, $_SWIFT["language"]["loggedout"]));
} else {
	if (!$session->start(SESSION_MONITOR)) {
		// Failed to load session
		$staffauth->displayLoginForm($_SWIFT["errorstr"]);
		exit;
	}
	
	// User logged in, trigger events
	if (!$events->triggerEvent(EVENT_MONITOR))
	{
		echo '<a href="?_ca=logout">Logout?</a>';
	}
}
?>